package com.mikufufu.blog.mapper;

import com.mikufufu.blog.model.dto.admin.SearchArticleParam;
import com.mikufufu.blog.model.entity.Article;
import com.mikufufu.blog.model.vo.admin.ArticleVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

public interface ArticleMapper extends BaseMapper<Article> {

    ArticleVO getArticleById(@Param("id") Integer id);

    IPage<ArticleVO> getArticlePage(IPage<ArticleVO> page, @Param("article") SearchArticleParam article, @Param("tagIds") List<Integer> tagIds);

    ArticleVO getTopArticle();

    Boolean setTopArticle(@Param("articleId") Integer articleId);

    Long getWordCount();

    /**
     * 获取上一篇和下一篇
     * {@link MapKey} 注解，指定返回结果的key,要求返回结果的key为指定的字段，否则会报错
     * @param id 当前文章id
     * @param collectionId 当前文章合集id
     * @return 上一篇文章和下一篇文章
     */
    @MapKey("key")
    Map<String, ArticleVO> getPreAndNextArticle(@Param("id") Integer id,@Param("collectionId") Integer collectionId);
}